<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>请假申请</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../common/mui/mui.css" rel="stylesheet" />
		<link href="../../common/css/yahei.css" rel="stylesheet" />
		<link href="../../common/css/iconfont.css" rel="stylesheet" />
		<link href="../../common/css/app.css" rel="stylesheet" />
		<link href="../../common/mui/mui.picker.min.css" rel="stylesheet" />
		<link href="../../dependence/wkplatform/css/ky/kyNewPublic.css" rel="stylesheet" />
		<link href="../../dependence/wkplatform/css/pmLeaveAppAdd.css" rel="stylesheet" />
		
	</head>
	<body class="YaHei">
		<header class="mui-bar mui-bar-nav borderB">
			<a class="mui-action-back mui-icon mui-icon-closeempty mui-pull-left"></a>
			<h1 class="mui-title ">新建</h1>
			<div id="submitBtn" data-id="Y" class="submitBtn">提交</div>
		</header>
		<div class="mui-content">
			<ul id="UL" class="mui-table-view">
				<li class="mui-table-view-cell">
					<div class="cellIcon"><div class="nurfont nur-wode-moren"></div></div>
					<div class="cellContent">
						<div class="cellTip">申请人：</div>
						<div id="applyer" class="rightText"></div>
					</div>
				</li>
				<li class="mui-table-view-cell">
					<div class="cellIcon"><div class="nurfont"></div></div>
					<ul class="mui-table-view">
						<li class="mui-table-view-cell">
							<div class="cellContent">
								<div class="cellTip">申请科室：</div>
								<div id="ward" class="rightText"></div>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div class="cellContent">
								<div class="cellTip">年龄：</div>
								<div id="age" class="rightText"></div>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div class="cellContent">
								<div class="cellTip">层级：</div>
								<div id="level" class="rightText"></div>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div class="cellContent">
								<div class="cellTip">学历：</div>
								<div id="education" class="rightText"></div>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div class="cellContent">
								<div class="cellTip">职称：</div>
								<div id="duty" class="rightText"></div>
							</div>
						</li>
					</ul>
				</li>
				<li class="mui-table-view-cell canSelect">
					<div class="cellIcon"><div class="nurfont nur-rili"></div></div>
					<div class="cellContent">
						<div class="cellTip">申请日期：</div>
						<div id="applyDate" class="rightText dateType"></div>
						<div class="mui-icon mui-icon-arrowright"></div>
					</div>
				</li>
				<li class="mui-table-view-cell">
					<div class="cellIcon"><div class="nurfont nur-shuqian"></div></div>
					<div class="cellContent">
						<div class="cellTip">状态：</div>
						<div id="status" class="rightText"></div>
					</div>
				</li>
				<li class="mui-table-view-cell">
					<div class="cellIcon"><div class="nurfont nur-shuqian"></div></div>
					<div class="cellContent">
						<div class="cellTip">现工作岗位：</div>
						<div id="currPosition" class="rightText"></div>
					</div>
				</li>
				<li class="mui-table-view-cell canSelect">
					<div class="cellIcon"><div class="nurfont nur-shuqian"></div></div>
					<div class="cellContent">
						<div class="cellTip">拟申请岗位：</div>
						<div id="appPosition" class="rightText"></div>
						<div class="mui-icon mui-icon-arrowright"></div>
					</div>
				</li>
				<li class="mui-table-view-cell">
					<div class="cellIcon"><div class="nurfont nur-jilu"></div></div>
					<div class="cellContent">
						<div class="cellTip">申请变动理由：</div>
						<div class="rightText mui-input-row">
							<input id="reason" type="text" class="mui-input-clear">
						</div>
					</div>
				</li>
			</ul>
		</div>
		<div id="positionPopo" class="mui-popover positionPopo">
			<div class="typeHeader">拟申请岗位</div>
			<div class="mui-scroll-wrapper">
				<div id="positionScroll" class="mui-scroll"></div>
			</div>
			<div class="bottomArea">
				<div class="cancelBtn">取消</div>
				<div class="sureBtn">确定</div>
			</div>
		</div>
		<script src="../../common/mui/mui.js"></script>
		<script src="../../common/mui/mui.picker.min.js"></script>
		<script src="../../common/js/jquery-3.4.1.min.js"></script>
		<script src="../../dependence/teach/js/teachDate.js"></script>
		<script src="../../common/js/app.js"></script>
		<script src="../../common/js/globalSet.js"></script>
		<script src="../../common/js/DHCWebService.js"></script>
		<script>
var perInfo,pageType,rw="";
	mui.init();
	mui.plusReady(function() {
		baseSetup();
	})
	if (!mui.os.plus) {
		baseSetup()
	}
	//N:已保存 Y:已提交 HZ：护士长审核  KH：科护士长审核 B：驳回 A:审核通过
	function submitBtnTapped(){
		var appDate = mui('#applyDate')[0].innerText
		if (appDate == "") {
			mui.toast('请选择申请日期')
			return
		}
		var appPosition = mui('#appPosition')[0].getAttribute('data-id')
		if (!appPosition || appPosition == "") {
			mui.toast('请选择拟申请岗位')
			return
		}
		var reason = mui('#reason')[0].value
		if (reason == "") {
			mui.toast('请填写申请理由')
			return
		}
		var parr = 'AppWard|^AppNur|'+perInfo.loginName+'^AppDate|'+appDate+'^AppStatus|^AppNurLevel|'+mui('#level')[0].getAttribute('data-id')+
			'^AppNurAge|'+mui('#age')[0].innerText+'^AppReason|'+reason+'^AppNurDuty|'+mui('#duty')[0].getAttribute('data-id')+
			'^AppNurAcade|'+mui('#education')[0].getAttribute('data-id')+'^AppPosition|'+mui('#currPosition')[0].getAttribute('data-id')+
			'^AppWPosition|'+mui('#appPosition')[0].getAttribute('data-id')+'^AppNurID|^RowID|'+rw+'^AppNurRW|';
		var pdict = {'parr':parr,flag:'Y','nurseid':perInfo.loginID}
		//console.log(parr);
		var paramDict = {'method':'web.INMPersonComm:SavePositionApp','params':JSON.stringify(pdict),'type':'RecMethod'}
		mui.DHCWebService(paramDict, function(result) {
			console.log(JSON.stringify(result));
			if (result['msg'] != '1') {
				mui.toast(msg)
				return
			}
			var listPage = plus.webview.getWebviewById('../WKPlatformPages/leave/pmLeaveApply.html')
			listPage.evalJS("detailChanged()")
			mui.back()
		}, function(errorStr) {
			mui.toast('请重试')
		});
	}
	
	
	function getDetailInfo(id){
		var pdict = {'id':id}
		var paramDict = {'method':'web.INMPersonComm:GetTransPosition','params':JSON.stringify(pdict),'type':'RecMethod'}
		mui.DHCWebService(paramDict, function(result) {
			console.log(JSON.stringify(result))
			var dataDict = result['data']
			if (!dataDict) {
				mui.toast('请重试')
				return 
			}
			mui('#age')[0].innerHTML = dataDict['AppNurAge']
			mui('#duty')[0].innerHTML = dataDict['AppNurDuty']
			mui('#applyDate')[0].innerHTML = dataDict['AppDate']
			mui('#status')[0].innerHTML = dataDict['AppStatus']
			
			updateDomUI('level',dataDict['AppNurLevel'],'护士层级','Desc');
			updateDomUI('education',dataDict['AppNurAcade'],'学历','Desc');
			updateDomUI('currPosition',dataDict['AppPosition'],'岗位名称');
			updateDomUI('appPosition',dataDict['AppWPosition'],'非护理岗');
			
			mui('#reason')[0].value = dataDict['AppReason'];
		}, function(errorStr) {
			mui.toast('请重试')
		});
	}
	
	//获取个人信息
	function getPerInfo(){
		var pdict = {'id':perInfo.loginID}
		var paramDict = {'method':'web.INMPersonComm:GetPerson','params':JSON.stringify(pdict),'type':'RecMethod'}
		//console.log(JSON.stringify(pdict))
		mui.DHCWebService(paramDict, function(result) {
			// console.log(JSON.stringify(result))
			var dataDict = result['data']
			mui('#age')[0].innerHTML = dataDict['PerAge']
			updateDomUI('level',dataDict['PerNurseLevel'],'护士层级');
			updateDomUI('education',dataDict['PerCurrentAcade'],'学历');
			updateDomUI('duty',dataDict['PerHireDuty'],'聘任职称');
			updateDomUI('currPosition',dataDict['PerPostName'],'岗位名称');
		}, function(errorStr) {
			mui.toast('请重试')
		});
	}
	
	function updateDomUI(domId,destStr,listType,valueType){
		var dom = mui('#'+domId)[0]
		if (destStr==undefined || destStr == "") {
			dom.innerHTML = ""
			dom.setAttribute('data-id',"")
			return 
		}
		if (valueType == 'Desc') {
			dom.innerHTML = destStr
		}else{
			dom.setAttribute('data-id',destStr)
		}
		getList(listType,destStr,valueType,function(dict){
			if (valueType == 'Desc') {
				dom.setAttribute('data-id',dict['SubValue'])
			}else{
				dom.innerHTML = dict['SubDesc']
			}
			
		})
	}
	
	//下拉框 岗位名称 护士层级 聘任职称 学历
	function getList(type,value,valueType,block,show){
		var pdict = {'type':type}
		var paramDict = {'method':'web.INMDBComm:FindPubCode','params':JSON.stringify(pdict),'type':'Query'}
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var dataArr = result['data']
			if (type == '非护理岗') {
				updatePostUL(dataArr)
				if (show) {
					mui('#positionPopo').popover('show')
					return
				}
			}
			var keyStr = 'SubValue'
			if (valueType == 'Desc') {
				keyStr = 'SubDesc'
			}
			mui.each(dataArr,function (index,oneDict) {
				if (oneDict[keyStr] == value) {
					if (block) {
						block(oneDict)
					}
					return false
				}
			})
		}, function(errorStr) {
			mui.toast('请重试')
		});
	}
	
	function updatePostUL(dataArr){
		var appPosition = mui('#appPosition')[0]
		var positionScroll = mui('#positionScroll')[0]
		var html = ''
		for (var i = 0; i < dataArr.length;i++) {
			var oneDict = dataArr[i]
			var active = ''
			if (rw!="" && appPosition.getAttribute('data-id') == oneDict['SubValue']) {
				active = ' mui-active'
			}
			html +='<div class="postItem'+active+'" data-id="'+oneDict['SubValue']+'">'+oneDict['SubDesc']+'</div>';
		}
		positionScroll.innerHTML = html
		mui('#positionScroll .postItem').each(function (index,element) {
			element.addEventListener('tap',function(){
				var oldActive = mui('#positionScroll .mui-active')[0];
				if (oldActive) {
					oldActive.classList.remove('mui-active')
				}
				this.classList.add('mui-active')
			})
		})
	}
	//选择日期
	function selectDate(){
		mui('#reason')[0].blur();
		var _self = this
		if(_self.picker) {
			_self.picker.show(function(rs) {
				_self.innerText = rs.text
				_self.classList.remove('noTextTip')
				_self.picker.dispose();
				_self.picker = null;
			});
		} else {
			var optionsJson = '{"type":"date"}';
			var options = JSON.parse(optionsJson);
			_self.picker = new mui.DtPicker(options);
			_self.picker.show(function(rs) {
				_self.innerText = rs.text
				_self.classList.remove('noTextTip')
				_self.picker.dispose();
				_self.picker = null;
			});
		}
	}
	function baseSetup(){
		mui('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		perInfo = app.getState()
		var self = plus.webview.currentWebview()
		pageType = self.title
		var sourceData = self.sourceData
		if (sourceData) { //新建
			mui('.mui-title')[0].innerText = '修改';
			rw = sourceData['RowID']
			getDetailInfo(rw)
		}else{
			mui('#applyDate')[0].innerText = getCurrentDeviceDay()
			getPerInfo();
		}
		mui('#applyer')[0].innerText = perInfo['loginName']
		mui('#ward')[0].innerHTML = perInfo['loginWardDesc']
		
		mui('#UL').on('tap','#applyDate',selectDate);
		mui('#UL').on('tap','#appPosition',function(){
			mui('#reason')[0].blur();
			if (mui('#positionScroll')[0].innerText == '') {
				getList('非护理岗','','',undefined,true)
			}else{
				mui('#positionPopo').popover('show');
			}
		});
		mui('#positionPopo').on('tap','.cancelBtn',function(){
			mui('#positionPopo').popover('hide');
		})
		mui('#positionPopo').on('tap','.sureBtn',function(){
			var activeDom = mui('#positionScroll .mui-active')[0]
			if (!activeDom) {
				mui.toast('请选择')
				return
			}
			mui('#appPosition')[0].innerText = activeDom.innerText
			mui('#appPosition')[0].setAttribute('data-id',activeDom.getAttribute('data-id'))
			mui('#positionPopo').popover('hide');
		})
		mui('body').on('tap','#submitBtn',submitBtnTapped) 
	}
/*
	{"AffirmLevel":"","AuditReason":"同意","AuditTime":"57813","CurrentAddress":"","CurrentArea":"","CurrentCity":"","CurrentProvince":"","Email":"",
	"HISNO":"","HomeAddress":"","HomeArea":"","HomeCity":"","HomeProvince":"","ImportDate":"2020-07-24","ImportUser":"","InTrainCurrentAcade":"",
	"NativeAddress":"","NativeArea":"顺义区","NativeCity":"北京市","NativeProvince":"北京市","PerAddress":"","PerAge":"23","PerAllowance":"",
	"PerAssToNurse":"","PerAssToStu":"","PerAttriDepart":"27||1","PerAuditDate":"2022-02-26","PerAuditFlag":"Y","PerAuditor":"0",
	"PerBirthday":"1999-03-20","PerCadreDate":"","PerCardId":"110101199903204388","PerCareType":"N","PerCategroy":"","PerClothesNo":"",
	"PerComeDate":"2017-06-23","PerContact":"","PerContactPhone":"","PerCurrentAcade":"3||3","PerCurrentDegree":"","PerCurrentSchool":"18||12",
	"PerDepDR":"1","PerDepDate":"","PerEspecially":"","PerForeignLevel":"25||3","PerHeight":"","PerHireDuty":"12||3","PerHireDutyDate":"2019-01-02",
	"PerHireJob":"","PerHobby":"","PerHomeAddress":"","PerHosShortNo":"","PerHouseAddress":"","PerID":"9994","PerInNursePost":"62||1","PerInitialAcade":"3||1",
	"PerInitialDegree":"15||1","PerInitialSchool":"18||1","PerInternDate":"","PerInternEndDate":"","PerInternSchool":"","PerInternStDate":"",
	"PerInternToStu":"","PerIsEspecially":"","PerIsRegiste":"1","PerIsSpeciNurse":"ICU专科护士","PerLRetireDate":"2054-03-06","PerLocDR":"",
	"PerMarriage":"4||2","PerName":"张芮菲","PerNation":"1||1","PerNativePlace":"","PerNo":"","PerNurTime":"1817","PerNurType":"","PerNurseLevel":"19||1",
	"PerPhone":"13501049819","PerPic":"Fileupdate/images/head/2.jpg?t=10","PerPolitDate":"","PerPolitical":"2||3","PerPostCategory":"","PerPostCompete":"",
	"PerPostDuty":"","PerPostDutyDate":"","PerPostName":"","PerPostType":"","PerRegNo":"111111","PerRegRegiDate":"2015-11-05","PerRegValidDate":"2020-11-03",
	"PerRemark":"","PerResignDate":"","PerRetireDate":"","PerSJHireDuty":"","PerSJHireDutyDate":"","PerSexDR":"6||2","PerShoesNo":"","PerSocialWork":"",
	"PerSocietyPart":"","PerSource":"7||9","PerStateDate":"","PerStatuReason":"","PerStatus":"17||1","PerStuToAss":"","PerStuToNurse":"","PerTrainEndDate":"",
	"PerTrainFee":"","PerTrainFlag":"","PerTrainStDate":"","PerTransFlag":"","PerTrialDate":"","PerTrialQual":"","PerTrialWork":"","PerTrouserNo":"","PerType":"",
	"PerTypeDR":"N","PerUnit":"","PerUserDR":"","PerWeight":"","PerWordType":"","PerWorkDate":"2017-06-23","PerYear":"","PrepareDate":"","RecDate":"","RecTime":"",
	"RecUser":"","RegistedAddress":"","RegistedArea":"","RegistedCity":"","RegistedProvince":"","Relationship":"","RowID":"2","SelfAssessLevel":""}
*/ 
		</script>
	</body>
</html>
